DB server side improved some problems when showing bookings remain
[RRRRHHHH_Code] / ruralHouses client / src / gui / listOfBookingRequestsGUI.java
index 3db660d..aab2736 100644 (file)
@@ -8,7 +8,6 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.rmi.Naming;
 import java.rmi.RemoteException;
-import java.util.Date;
 import java.util.Enumeration;
 import java.util.Vector;
 
@@ -23,7 +22,7 @@ import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.DefaultTableModel;
 
 import common.BookingInterface;
-import common.OfferInterface;
+
 import configuration.___IntNames;
 import domain.Booking;
 import domain.Offer;
@@ -63,16 +62,24 @@ public class listOfBookingRequestsGUI extends JFrame {
                setContentPane(contentPane);
                contentPane.setLayout(null);
 
-               this.bookings = this.off.getBookings();
+               try {
+                       bookM = (BookingInterface) Naming
+                                       .lookup(___IntNames.BookingManager);
+
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               try {
+                       this.bookings = bookM.getOffersbookings(this.off);
+               } catch (RemoteException e1) {
+                       e1.printStackTrace();
+               }
+
                JLabel lblNewLabel = new JLabel();
                lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
                lblNewLabel.setBounds(23, 41, 536, 33);
                contentPane.add(lblNewLabel);
-               if (bookings.isEmpty())
-                       lblNewLabel
-                                       .setText("There are not bookings to be confirmed or denied");
-               else
-                       lblNewLabel.setText("List of bookings:");
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
                scrollPane.setBounds(23, 113, 536, 271);
@@ -92,17 +99,11 @@ public class listOfBookingRequestsGUI extends JFrame {
 
                table.setModel(tableModel);
 
+               JButton btnDenyAddition = new JButton("Deny Booking");
                JButton btnNewButton = new JButton("Confirm Booking");
                btnNewButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
-                               try {
-                                       bookM = (BookingInterface) Naming
-                                                       .lookup(___IntNames.BookingManager);
-                               } catch (Exception e1) {
-                                       System.out
-                                                       .println("Error accessing remote authentication: "
-                                                                       + e1.toString());
-                               }
+
                                if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
                                        if (table.getRowCount() != 0
                                                        && table.getSelectedRow() != -1) {
@@ -112,6 +113,19 @@ public class listOfBookingRequestsGUI extends JFrame {
                                                } catch (RemoteException e1) {
                                                        e1.printStackTrace();
                                                }
+                                               int rows = table.getModel().getRowCount(); 
+                                               for(int i = rows - 1; i >=0; i--){
+                                                       ((DefaultTableModel) table.getModel()).removeRow(i);
+                                               }
+                                               Vector<Object> row = new Vector<Object>();
+                                               row.add(book.getBookNumber());
+                                               row.add(book.getBookDate());
+                                               row.add(book.getClient().getName());
+                                               row.add(book.getClient().getMailAccount());
+                                               row.add(book.getClient().getTelephone());
+                                               tableModel.addRow(row);
+                                               btnNewButton.setEnabled(false);
+                                               btnDenyAddition.setEnabled(false);
                                        }
 
                                }
@@ -120,17 +134,9 @@ public class listOfBookingRequestsGUI extends JFrame {
                btnNewButton.setBounds(33, 396, 169, 25);
                contentPane.add(btnNewButton);
 
-               JButton btnDenyAddition = new JButton("Deny Booking");
                btnDenyAddition.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
-                               try {
-                                       bookM = (BookingInterface) Naming
-                                                       .lookup(___IntNames.BookingManager);
-                               } catch (Exception e1) {
-                                       System.out
-                                                       .println("Error accessing remote authentication: "
-                                                                       + e1.toString());
-                               }
+
                                if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
                                        Booking book = bookings.get(table.getSelectedRow());
                                        try {
@@ -138,11 +144,24 @@ public class listOfBookingRequestsGUI extends JFrame {
                                        } catch (RemoteException e) {
                                                e.printStackTrace();
                                        }
+                                       ((DefaultTableModel) table.getModel()).removeRow(table
+                                                       .getSelectedRow());
                                        bookings.remove(book);
 
                                }
                        }
                });
+               if (bookings.isEmpty())
+                       lblNewLabel
+                                       .setText("There are not bookings to be confirmed or denied");
+               else {
+                       lblNewLabel.setText("List of bookings:");
+                       if (this.bookings.get(0).getOffer().isBooked()) {
+                               btnDenyAddition.setEnabled(false);
+                               btnNewButton.setEnabled(false);
+                       }
+               }
+
                btnDenyAddition.setBounds(390, 395, 169, 25);
                contentPane.add(btnDenyAddition);
 
@@ -164,10 +183,6 @@ public class listOfBookingRequestsGUI extends JFrame {
                         */
                        private static final long serialVersionUID = 1L;
 
-                       public int daysBetween(Date d1, Date d2) {
-                               return (int) ((d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
-                       }
-
                        @Override
                        public Component getTableCellRendererComponent(JTable table,
                                        Object value, boolean isSelected, boolean hasFocus,
@@ -176,10 +191,7 @@ public class listOfBookingRequestsGUI extends JFrame {
                                super.getTableCellRendererComponent(table, value, isSelected,
                                                hasFocus, row, col);
 
-                               Date bookDay = (Date) table.getModel().getValueAt(row, 1);
-                               Date currentDay = new java.util.Date(System.currentTimeMillis());
-
-                               if (daysBetween(bookDay, currentDay) > 3) {
+                               if (!bookings.get(row).getOffer().isBooked()) {
                                        setBackground(Color.RED);
                                        setForeground(Color.BLACK);
                                } else {